package data;

import java.util.LinkedList;

import factory.MenuStarter;
import factory.OrderObject;

/**
 * @author Steve
 * Order class
 */
public class Order {
	private static OrderObject itemOrder;
	private static int register;

	/**
	 * Default constructor
	 */
	public Order(){
		itemOrder = null;
		register = 0;
	}

	/**
	 * @param order OrderObject
	 */
	public Order(OrderObject order){
		itemOrder = order;
		register = 0;
	}

	/**
	 * @param order OrderObject
	 */
	public Order(Order order){
		this.itemOrder = order.itemOrder;
		this.register = order.register;
	}

	/**
	 * @param register placeholder for the register num
	 * @param order placeholder for OrderObject
	 */
	public Order(int register, OrderObject order){
		this.register = register;
		itemOrder = order;
	}

	/**
	 * @return register
	 */
	public int getRegister() {
		return register;
	}

	/**
	 * @param register assigns a register
	 */
	public void setRegister(int register) {
		this.register = register;
	}

	/**
	 * @return OrderObject
	 */
	public static OrderObject getOrder() {
		return itemOrder;
	}

	/**
	 * @param order takes an order
	 * @return 
	 */
	public static Order takeOrder() {
		itemOrder = MenuStarter.getOrder();
		return new Order(register, itemOrder);
	}

	/** 
	 * @return order in a receipt fashion.  In tiers
	 */
	public String toString(){
		return itemOrder.toString();
	}

	/**
	 * @return single string of entire order
	 */
	public static String toLine(){
		return itemOrder.toLine();
	}

	/**
	 * @return subtotal of order
	 */
	public double getSubtotal() {
		double num = 0, temp = 0;
		LinkedList<String> args = new LinkedList<String>();
		for(String arg : toLine().trim().split(","))
			args.add(arg);
		while(!args.isEmpty()){

			try{
				temp = 0;
				temp = Double.parseDouble(args.peek());
				args.pop();
			} catch (NumberFormatException nfe) {
				args.pop();
			}
			num += temp;
		}
		return num;
	}

	public static void main(String[] args){
//		takeOrder();
//		double num = getSubtotal();
//		System.out.println(num);
	}
}
